package com.zcf.controller;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zcf.common.json.Body;
import com.zcf.pojo.Airlines;
import com.zcf.service.AirlinesServiceImpl;
import com.zcf.vo.out.LayuiJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author jj
 * @date 2019/10/15 11:30
 * 客服
 */
@CrossOrigin
@Controller
@RequestMapping(value = "/Airlines")
public class AirlinesController {

    @Autowired
    private AirlinesServiceImpl airlinesService;
    /**
     * @description :添加客服
     * @param airlines
     * @return: java.util.List<com.ggh.entity.Airlines>
     * @date : 2019/10/14 15:44
     * @author : jj
     * @throws
     */
    @PostMapping(value = "/add")
    @ResponseBody
    public Body add(Airlines airlines) {
        Body body = airlinesService.add(airlines);
        return body;
    }

    /**
     * 查询全部
     * @return
     */
    @PostMapping(value = "/findAll")
    @ResponseBody
    public LayuiJson fandAll(@RequestParam("type") Integer type) {
        System.out.println(type);
        Airlines airlines=new Airlines();
        List<Airlines> airlinesList = airlines.selectList(new EntityWrapper().eq("type",type));
        //联系客服
        LayuiJson lj = new LayuiJson();
        if (airlinesList != null) {
            lj.setCode(0);
            lj.setCount(airlinesList.size());
            lj.setData(airlinesList);
            lj.setMsg("成功");
            return lj;
        }
        lj.setCode(1);
        lj.setCount(0);
        lj.setData(null);
        lj.setMsg("暂无数据");
        return lj;
    }
    /**
     * 删除客服
     */
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Body delete(Airlines airlines) {
        Body body = airlinesService.delete(airlines);
        return body;
    }
    /**
     * 更新客服
     */
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    @Transactional(rollbackFor = Exception.class)
    public Body update(Airlines airlines) {
        boolean isUpdated = airlines.updateById();
        if (!isUpdated){
            return Body.newInstance(500,"参数错误！");
        }
        return Body.newInstance();
    }
}
